package com.treasure.service.task.job.pay;

import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/7/15.
 */
@DisallowConcurrentExecution
public class CancelSignAgreementJob implements Job {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public CancelSignAgreementJob(){
    }

    @Autowired
    RestTemplate restTemplate;

    @Value("${yingu.api.oneself.gateway}")
    private String requestUrl;

    public void execute(JobExecutionContext context)
        throws JobExecutionException {
        JobKey key = context.getJobDetail().getKey();
        long start = System.currentTimeMillis();
        logger.info("检查需要退款的签约任务开始运行 Instance " + key);
        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
        restTemplate.postForObject(requestUrl+"/pay_buy/buy/cancelBatchSignAgreementJob",requestEntity,String.class);
        logger.info("检查需要退款的签约任务结束运行 Instance " + key+ ":{}",(System.currentTimeMillis()-start));
    }
}
